package cn.jekun.web.shop.service;

import java.sql.Types;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.jekun.component.base.bean.Page;
import cn.jekun.component.base.utils.SqlUtis;
import cn.jekun.component.core.bean.gen.RsUser;
import cn.jekun.component.core.bean.gen.RsUserShop;
import cn.jekun.component.core.service.ComponentCoreService;
import cn.jekun.component.core.service.gen.RsUserService;
import cn.jekun.web.shop.bean.Shop;
import cn.jekun.web.shop.bean.UserShop;
@Service(UserShopService.BEAN_NAME)
public class UserShopService extends ComponentCoreService{
	public static final String BEAN_NAME="cn.jekun.web.shop.service.UserShopService";
	public static final String NAMESPACE="ACTION_USER_SHOP";
	
	@Resource(name=RsUserService.BEAN_NAME)
	RsUserService userService;
	
	@Override
	public String getNamespace() {
		return NAMESPACE;
	}
	
	
	
	
	public List<UserShop> getQueryUserList(@RsUserShop.AnnoShopId String shopId,@RsUserShop.AnnoStaffId String staffId,
										   @RsUser.AnnoRealName String realName,Page page){
		Map formMap=new HashMap<String, String>();
		
		formMap.put(Shop.COL_SHOP_ID, shopId);
		formMap.put(UserShop.STAFF_ID, staffId);
		formMap.put(UserShop.REAL_NAME, realName);
		SqlUtis.prepareSql(formMap, SqlUtis.getSQL(formMap,
				"a." + Shop.COL_SHOP_ID, Types.VARCHAR, SqlUtis.EQ),
				SqlUtis.getSQL(formMap,"a."+UserShop.STAFF_ID,Types.VARCHAR,SqlUtis.LIKE),
				SqlUtis.getSQL(formMap,"b."+UserShop.REAL_NAME,Types.VARCHAR,SqlUtis.LIKE));
		return this.list(formMap, page);
	}

	
	/**
	 * 修改密码
	 * @param rsUser
	 */
	@Transactional
	public void updatePassword(@RsUser.AnnoUserId String userId,@RsUser.AnnoPassword String password){
		RsUser rsUser = new RsUser();
		rsUser.setPassword(password);
		rsUser.setUserId(userId);
	    Map formMap  = new HashMap();
	    formMap.put("rsUser", rsUser);
	    formMap.put(RsUser.COL_USER_ID, rsUser.getUserId());
	    formMap.put(RsUser.COL_REAL_NAME, rsUser.getRealName());
		SqlUtis.prepareSql(formMap, "",
				SqlUtis.getSQLRequired(formMap, "a."+RsUser.COL_USER_ID, Types.VARCHAR));
		this.userService.update(formMap);
	}
}
